package com.fingard.dsp.bank.reqrespobj;

import java.text.ParseException;
import java.util.Date;

import com.fingard.constant.Format;
import com.fingard.text.StringHelper;

public class ReqRespHeader {
    /**
     * 线路代码  （如 NNBill01 表示快钱）
     */
    public String bankCode;

    /**
     * 账户分组     （默认:Default）
     */
    public String group;
    
    /**租户*/
    public String tenant = "";

    /**
     * 所属公司 （默认：5000001）
     */
    public String corporation;

    /**
     * 指令类型 （如7506余额查询）
     */
    public String transType;

    /**
     * 指令代码   （如190801 单笔实时付款）
     */
    public String commandCode;

    /**
     * 账户结构
     */
    public String actBankType;

    /**
     * 指令流水号
     */
    public String transSeqID;

    /**
     * 指令请求时间
     */
    public String transTime;

    public PacketType pckType;

    public String bankFrontCode;

    public String psselNum;
    
    /**批量代收付时，为支付批号，节点<ReqSeqID>
     * 单笔支付时，为支付流水号，节点<ReqSeqID>
     * 单笔合批支付时，为合批支付批号，节点<ReqBatchNO>*/
    public String reqSeqOrBatNo;

    /**支付批号（批量）或支付流水号（单笔）*/
    public String reqSeqID;

    /**银行流水号*/
    public String outTransID;

    public String payDateTime;

    /**本方账号*/
    public String ownAct;

    /**票据号*/
    public String billNo;

    /**协议号*/
    public String protocolNo;

    /**订单类型*/
    public String  orderType;
    
    /**系统银行代码，如102工行，308招行，
     * 应用场景举例：用于回单同步时，根据银行代码取文件保存主目录*/
    public String syBank;
    /**是否为批量代收（代扣）*/
    public boolean isBatRec = false;
    /**是否为批量代付*/
    public boolean isBatPay = false;
    
    /**是否为重发指令*/
    public boolean isReSend = false;

    /** 原有bankcode */
    public String srcBankCode = "";

    /** 是否单笔转批量 */
    public boolean isFromSinglePay = false;
	
	    /**是否查询出票状态*/
    public boolean isQryBillApply = false;

    public String step = "";

    /**
     * 日志号
     */
    public String logTransID = "";

    public ReqRespHeader clone() {
        ReqRespHeader retHeader = new ReqRespHeader();
        retHeader.bankCode = this.bankCode;
        retHeader.group = this.group;
        retHeader.tenant = this.tenant;
        retHeader.corporation = this.corporation;
        retHeader.transType = this.transType;
        retHeader.commandCode = this.commandCode;
        retHeader.actBankType = this.actBankType;
        retHeader.transSeqID = this.transSeqID;
        retHeader.transTime = this.transTime;
        retHeader.pckType = this.pckType;
        retHeader.bankFrontCode = this.bankFrontCode;
        retHeader.psselNum = this.psselNum;
        retHeader.reqSeqID = this.reqSeqID;
        retHeader.reqSeqOrBatNo = this.reqSeqOrBatNo;
        retHeader.payDateTime = this.payDateTime;
        retHeader.ownAct=this.ownAct;
        retHeader.protocolNo=this.protocolNo;
        retHeader.billNo=this.billNo;
        retHeader.outTransID=this.outTransID;
        retHeader.syBank = this.syBank;
        retHeader.isBatPay = this.isBatPay;
        retHeader.isBatRec = this.isBatRec;
        retHeader.isReSend = this.isReSend;
        retHeader.orderType=this.orderType;
        retHeader.isQryBillApply=this.isQryBillApply;
        retHeader.isFromSinglePay = this.isFromSinglePay;
        retHeader.step = this.step;
        retHeader.logTransID = this.logTransID;
        return retHeader;
    }

    /**
     * 获取当前业务时间：
     * 1、先取PayDate+PayTime，
     * 2、没有则取TransTime，
     * 3、默认取p_default
     */
    public Date getBusTime(Date p_default) {
        if (StringHelper.hasAnyChar(payDateTime)) {
            try {
                return Format.DateTimeFormat.parse(payDateTime);
            } catch (ParseException e) {
                e.printStackTrace();
            }
        } else if (StringHelper.hasAnyChar(transTime)) {
            try {
                return Format.DateTimeFormat.parse(transTime);
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }

        return p_default;
    }

    public void setTransType(String p_transType) {
    	if(StringHelper.isNullOrEmpty(p_transType)){
    		transType="";
    		pckType = PacketType.Other;
    		return;
    	}
        transType = p_transType;
        if(p_transType.endsWith("-ReSend")){
        	this.isReSend = true;
        }
        if (p_transType.equals("7506") || p_transType.equals("7505")) {
            pckType = PacketType.OtherQuery;
        } else if (p_transType.equals("7516") || p_transType.equals("7515")) {
            pckType = PacketType.OtherQuery;
        } else if (p_transType.equals("7508")) { //余额信息对账查询接口、余额对账结果确认提交
            pckType = PacketType.OtherQuery;
        } else if (p_transType.equals("7509")) {
            pckType = PacketType.OtherQuery;
        } else if (p_transType.equals("B001") || p_transType.equals("B002") || p_transType.equals("B004") || p_transType.equals("B005") || p_transType.equals("B006") || p_transType.equals("B007") || p_transType.equals("B008")||p_transType.equals("B009")||p_transType.equals("B010")||p_transType.equals("B011")) { //电票
            pckType = PacketType.EleQuery;
        } else if (p_transType.equals("B003") || p_transType.equals("B101") || p_transType.equals("B102") || p_transType.equals("B103") || p_transType.equals("B104") || p_transType.equals("B105") || p_transType.equals("B106") || p_transType.equals("B107") || p_transType.equals("B108") || p_transType.equals("B109") || p_transType.equals("B110") || p_transType.equals("B111") || p_transType.equals("B112")||p_transType.equals("B113")||p_transType.equals("B119")) {
            pckType = PacketType.Ele;
        }else if (p_transType.equals("Bat101") ||p_transType.equals("Bat101Qry")||p_transType.equals("BOB01") || p_transType.equals("BOB02") || p_transType.equals("BOB03") || p_transType.equals("BOB04") || p_transType.equals("BOB05") || p_transType.equals("BOB06") || p_transType.equals("BOB07") || p_transType.equals("BOB08") || p_transType.equals("BOB09")) {
            pckType = PacketType.Other;
        }else if (p_transType.equals("1908") || p_transType.equals("1944") || p_transType.equals("6908") || p_transType.equals("6944") || p_transType.equals("1908BAT") || p_transType.equals("1944BAT")) {
            if (p_transType.equals("1908") || p_transType.equals("6908") || p_transType.equals("1908BAT")) {
                pckType = PacketType.Pay;
            } else {
                pckType = PacketType.PayQuery;
            }
        } else if (p_transType.equals("9108") || p_transType.equals("9144")) {
            if (p_transType.equals("9108")) {
                pckType = PacketType.Pay;
            } else {
                pckType = PacketType.PayQuery;
            }
        } else if (p_transType.equals("PurchaseFCP") || p_transType.equals("PurchaseFCSQ")) {//购汇
            if (p_transType.equals("PurchaseFCP")) {
                pckType = PacketType.Pay;
            } else {
                pckType = PacketType.PayQuery;
            }
        } else if (p_transType.equals("SettleFCP") || p_transType.equals("SettleFCSQ")) {//结汇
            if (p_transType.equals("SettleFCP")) {
                pckType = PacketType.Pay;
            } else {
                pckType = PacketType.PayQuery;
            }
        } else if (p_transType.equals("RealAuth") || p_transType.equals("RealAuthQuery")) {
            pckType = PacketType.Other;
        } else if (p_transType.equals("9110") || p_transType.equals("9146")) {
            if (p_transType.equals("9110")) {
                pckType = PacketType.Pay;
            } else {
                pckType = PacketType.PayQuery;
            }
        } else if (p_transType.equals("9109") || p_transType.equals("9145")) {
            if (p_transType.equals("9109")) {
                pckType = PacketType.Pay;
            } else {
                pckType = PacketType.PayQuery;
            }
        } else if (p_transType.equals("1988") || "1988-ReSend".equals(p_transType) || p_transType.equals("1998") || p_transType.equals("9188") || "9188-ReSend".equals(p_transType) || p_transType.equals("9198")) {
            if (p_transType.equals("1988") || "1988-ReSend".equals(p_transType) || p_transType.equals("9188") || "9188-ReSend".equals(p_transType)) {
                pckType = PacketType.Pay;
            } else {
                pckType = PacketType.PayQuery;
            }
        } else if (p_transType.equals("GenQRInfo") || p_transType.equals("SubmitQROrder") || p_transType.equals("QueryQRPay")) {
            if (p_transType.equals("SubmitQROrder")) {
                pckType = PacketType.Pay;
            } else {
                pckType = PacketType.PayQuery;
            }
        } else if (p_transType.equals("SubmitH5Order") || p_transType.equals("QueryH5Pay")) {
            if (p_transType.equals("SubmitH5Order")) {
                pckType = PacketType.Pay;
            } else {
                pckType = PacketType.PayQuery;
            }
        } else if (p_transType.equals("SubmitJSAPIOrder") || p_transType.equals("QueryJSAPIPay") || p_transType.equals("GenGetUserCodeURL")) {
            if (p_transType.equals("SubmitJSAPIOrder")) {
                pckType = PacketType.Pay;
            } else {
                pckType = PacketType.PayQuery;
            }
        } else if (p_transType.equals("CloseOrder") || p_transType.equals("CloseQROrder") || p_transType.equals("CloseGWOrder") || p_transType.equals("CloseJSAPIOrder") || p_transType.equals("CloseAPPOrder") || p_transType.equals("CloseH5Order")) {
            pckType = PacketType.CloseOrder;
        } else if (p_transType.equals("QryStatement")) {
            pckType = PacketType.OtherQuery;
        } else if (p_transType.equals("SendSmsCode")) {
            pckType = PacketType.Other;
        } else if (p_transType.equals("GenGwMap") || p_transType.equals("GWPAY") || p_transType.equals("QueryGwOrder")) { // 网关支付
            if (p_transType.equals("GenGwMap") || p_transType.equals("GWPAY")) {
                pckType = PacketType.Pay;
            } else {
                pckType = PacketType.PayQuery;
            }
        } else if (p_transType.equals("ENDIIMPT") || p_transType.equals("QENDIIMPT") || p_transType.equals("QueryRecAuthInfo")) {
            pckType = PacketType.Other;
        } else {
            pckType = PacketType.Other;
        }
    }
}
